package org.springframework.samples.petclinic

import java.util.ArrayList
import java.util.Collections
import java.util.HashSet
import java.util.List
import java.util.Set

import org.springframework.beans.support.MutableSortDefinition
import org.springframework.beans.support.PropertyComparator

class Vet(var specialties: java.util.Set[Specialty]) extends Person {
  
  def this() = this(null)
  
  protected def setSpecialtiesInternal(specialties:java.util.Set[Specialty]) = {
    this.specialties = specialties
  }

  protected def getSpecialtiesInternal:Set[Specialty] = {
    if (specialties == null) {
      specialties = new HashSet[Specialty]
    }
    specialties
  }
  
  def getSpecialties:List[Specialty] = {
    val sortedSpecs:List[Specialty] = new ArrayList[Specialty](getSpecialtiesInternal)
    PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true))
    Collections.unmodifiableList[Specialty](sortedSpecs) 
  }
  
  def getNrOfSpecialties():Int = getSpecialtiesInternal.size

  def addSpecialty(specialty:Specialty) = getSpecialtiesInternal.add(specialty)
}
